package com.baimifan.renovation.tools;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.widget.ImageView;
import android.widget.TextView;

import com.baimifan.renovation.R;

/**
 * Created by baimifan on 2017/06/22.
 */

public class NewLoadDialog extends Dialog {
    private TextView title;
    private ImageView img;
    private AnimationDrawable drawable;
    private String msg;
    public NewLoadDialog(@NonNull Context context, String msg) {
        super(context);
        this.msg = msg;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.loading_dialog);
        title = (TextView) findViewById(R.id.loading_title);
        img = (ImageView) findViewById(R.id.loading_img);
        title.setText(msg);
        img.setImageResource(R.drawable.dialog_load_anim);
    }

    @Override
    public void show() {
        super.show();
        drawable = (AnimationDrawable) img.getDrawable();
        drawable.start();
    }

    @Override
    public void dismiss() {
        super.dismiss();
        drawable = (AnimationDrawable) img.getDrawable();
        drawable.stop();
    }
}
